/*************************************************************************
 *
 *  Copyright (C) 2013 Florian Dang <florian.coin@gmail.com>
 *
 *  This file is part of NatusVerse.
 *
 *  NatusVerse is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  NatusVerse is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with NatusVerse.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************/

#ifndef INC_NBODY_BODY_H_
#define INC_NBODY_BODY_H_

/*!
 * \file        body.h
 * \brief       Body/particle for NBody problem
 * \author      Florian Dang
 * \date        2013
 *
 */

#include "graphics/graphics.h"

namespace nbody
{
//! Body/particle class
/*!
  Define the particle class for the N-body problem.
*/
class Body
{
	public:
		typedef color::t_color t_color;
		typedef graphics::Graphics Graphics;
		typedef Graphics::t_point t_point;
		typedef Graphics::t_vector t_vector;

		//! real gravity constant is 6.67e-11
		static const float kGravityConst;

		//! epsilon to avoid collision
		static const float kEpsCollision;

		//! max size for a particle
		static const int   kMaxParticleSize;

		//! define wether the particles bounces on the borders or not
		static const bool  kRebounce;

		//! Default constructor
		Body() {}

		//! Usual constructor
		Body(t_point p, float m, t_color c)
			: center_(p), velocity_(Graphics::kforce_orig_t), mass_(m), color_(c) {}

		//! Alternative constructor with velocity
		Body(t_point p, t_vector v, float m, t_color c)
			: center_(p), velocity_(v), mass_(m), color_(c) {}

		//! Destructor
		~Body() {}

		//! Center accessor
		t_point  center() const
		{
			return center_;
		}

		//! Velocity accessor
		t_vector velocity() const
		{
			return velocity_;
		}

		//! Mass accessor
		float    mass() const
		{
			return mass_;
		}

		//! Particle movement
		/*!
		  \param f a force
		  \param dt time step
		  Apply a force f with time step dt. This is a first order Euler scheme.
		*/
		void     Move(t_vector f, float dt);

		//! Compute the force applied from an other particle
		t_vector ForceFrom(Body body);

		//! Draw the particle
		void     Draw(Graphics win);

		//! Erase the particle
		void     Erase(Graphics win);

		//! Change the color of the particle
		void     ChangeColor();


	private:
		t_point  center_;    /*!< particle center coordinates */
		t_vector velocity_;  /*!< particle velocity */
		float    mass_;      /*!< particle mass */
		t_color  color_;     /*!< particle color */
};

} // end namespace

#endif  // INC_NBODY_BODY_H_
